import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { PetMingItemData } from "../info/PetMingItemData";
import { PetMingBaseItem } from "./PetMingBaseItem";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Cache } from "../../../cache/Cache";
import { PetMingUtil } from "../info/PetMingUtil";
import { NumAddEffect } from "../../effect/NumAddEffect";
import { DataEvent } from "../../../events/DataEvent";
import { Global } from "../../../../../com/gengine/global/Global";
import { GuideTipsManager } from "../../../manager/GuideTipsManager";
import { GuidePetLifeStyleRule } from "../../../rules/GuidePetLifeStyleRule";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { _EPlayerItemPosTypePetLifeStypeHunt } from "../../../../../EPlayerItemPosType/_EPlayerItemPosTypePetLifeStypeHunt";
import { _EPlayerItemPosTypePetLifeStypePut } from "../../../../../EPlayerItemPosType/_EPlayerItemPosTypePetLifeStypePut";
type int = number;
//class PetMingItemCellRenderer
    
    export  class PetMingItemCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            Dispatcher.addEventListener(EventName.PetMingOnkeyEatSuccess, this.onPetMingOnkeyEatSuccessHandler);
            Dispatcher.addEventListener(EventName.PetMingOnkeyGetSuccess, this.onPetMingOnkeyGetSuccessHandler);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._itemData = arg1 as PetMingItemData;
            this._mingBaseItem.itemData = this._itemData;
            if (this._itemData && this._itemData.isExpLifeStyle) 
            {
                this._getTxt.visible = false;
                this._eatTxt.x = 28;
            }
            else 
            {
                this._getTxt.visible = true;
                this._eatTxt.x = 45;
            }
            this.guideLifeStyleGet();
            return;
        }

        /* internal  */init(): void
        {
            this._bg = new Object /* flash.display.Bitmap */();
            this.addChild(this._bg);
            this._avatarbg = new Object /* flash.display.Bitmap */();
            this._avatarbg.x = 20;
            this._avatarbg.y = 10;
            this.addChild(this._avatarbg);
            this._mingBaseItem = new PetMingBaseItem();
            this._mingBaseItem.posType = EPlayerItemPosType._EPlayerItemPosTypePetLifeStypeHunt;
            this._mingBaseItem.isShowLevel = false;
            this._mingBaseItem.isDragAble = false;
            this._mingBaseItem.isDropAble = false;
            this._mingBaseItem.buttonMode = true;
            this._mingBaseItem.useHandCursor = true;
            this._mingBaseItem.setNamePos(-1, 35);
            this._mingBaseItem.move(14, 5);
            this._mingBaseItem.addEventListener(flash.events.MouseEvent.CLICK, this.onBaseItemClickHandler);
            this.addChild(this._mingBaseItem);
            this._getTxt = ObjCreate.createGTextField("", 10, 60, 50, 20, this, GlobalStyle.textFormatGreen);
            this._getTxt.htmlText = Language.getString(54767);
            this._eatTxt = ObjCreate.createGTextField("", 45, 60, 50, 20, this, GlobalStyle.textFormatGreen);
            this._eatTxt.htmlText = Language.getString(54766);
            this._eatTxt.addEventListener(flash.events.TextEvent.LINK, this.onLinkClickHandler);
            this._getTxt.addEventListener(flash.events.TextEvent.LINK, this.onLinkClickHandler);
            LoaderHelp.addResCallBack(ResFileConst.PetMing, this.onLoadedHandler);
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._bg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetMingItemBg);
            this._avatarbg.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetMingAvatarBg);
            return;
        }

        /* internal  */onLinkClickHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=0;
            if (Cache.instance.petMing.isDoReplay) 
            {
                return;
            }
            if (this._itemData) 
            {
                loc1 = int(arg1.text);
                this.operByType(loc1);
            }
            return;
        }

        /* internal  */eatSuccess(arg1: Map<any, any> /* flash.utils.Dictionary */, arg2: int): void
        {
            this.fly(PetMingItemCellRenderer.EAT, this.showAddExpEffect, arg2);
            this._itemData = null;
            return;
        }

        /* internal  */getSuccess(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            this.fly(PetMingItemCellRenderer.GET, null);
            this._itemData = null;
            return;
        }

        /* internal  */fly(arg1: int, arg2: Function=null, ... rest): void
        {
            var loc1=null;
            this._flyType = arg1;
            if (arg1 != PetMingItemCellRenderer.GET) 
            {
                loc1 = new Object /* flash.geom.Point */(680, 425);
            }
            else 
            {
                loc1 = new Object /* flash.geom.Point */(630, 335);
            }
            PetMingUtil.flyToJunWindowPoint(this._mingBaseItem.effectPlayer.bitmapData, this._mingBaseItem.localToGlobal(new Object /* flash.geom.Point */(this._mingBaseItem.x, this._mingBaseItem.y)), loc1, arg2, rest);
            return;
        }

        /* internal  */showAddExpEffect(... rest): void
        {
            var loc1=Cache.instance.petMing.juWindow;
            var loc2=loc1.localToGlobal(new Object /* flash.geom.Point */(705, 435));
            NumAddEffect.playAddNum(int(rest[0]), loc2.x, loc2.y);
            return;
        }

        /* internal  */onPetMingOnkeyGetSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            if (this._itemData && !(loc1[this._itemData.uid] == null) && Global.stage.contains(this) && this.visible) 
            {
                this.fly(1);
            }
            this._itemData = null;
            return;
        }

        /* internal  */onPetMingOnkeyEatSuccessHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as Map<any, any> /* flash.utils.Dictionary */;
            if (this._itemData && !(loc1[this._itemData.uid] == null) && Global.stage.contains(this) && this.visible) 
            {
                this.fly(2);
            }
            this._itemData = null;
            return;
        }

        /* internal  */onBaseItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (Cache.instance.petMing.isDoReplay) 
            {
                return;
            }
            if (this._itemData) 
            {
                if (this._itemData.isExpLifeStyle) 
                {
                    this.operByType(PetMingItemCellRenderer.EAT);
                }
                else 
                {
                    this.operByType(PetMingItemCellRenderer.GET);
                }
            }
            return;
        }

        /* internal  */operByType(arg1: int): void
        {
            var loc1=null;
            if (this._itemData) 
            {
                loc1 = new Map<any, any> /* flash.utils.Dictionary */();
                loc1[this._itemData.uid] = this._itemData.itemAmount;
                if (arg1 != PetMingItemCellRenderer.EAT) 
                {
                    if (arg1 == PetMingItemCellRenderer.GET) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingOneKeyGet, {"fromPosType": _EPlayerItemPosTypePetLifeStypeHunt, "toPosType": _EPlayerItemPosTypePetLifeStypePut, "itemUidDict": loc1, "callBackFun": this.getSuccess}));
                    }
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingEat, {"fromPosType": _EPlayerItemPosTypePetLifeStypeHunt, "fromPetUid":"", "itemDict": loc1, "callBackFun": this.eatSuccess, "exp": this._itemData.effect}));
                }
            }
            return;
        }

        /* internal  */guideLifeStyleGet(): void
        {
            var loc1=null;
            var loc2=null;
            this._getTxt.mouseEnabled = true;
            this._eatTxt.mouseEnabled = true;
            if (GuideTipsManager.guideTips.parent == this) 
            {
                GuideTipsManager.hideGuideTips();
            }
            var loc3=Cache.instance.guidePetLifeStyle.stepGetLifeStyle;
            switch (loc3) 
            {
                case GuidePetLifeStyleRule.StepLifeStyleGet1:
                {
                    if (this._getTxt.visible == false) 
                    {
                        loc1 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_TL, Language.getString(27204));
                        loc1.x = this._eatTxt.x + 18;
                        loc1.y = this._eatTxt.y + 18;
                        addChild(loc1);
                        this._getTxt.mouseEnabled = false;
                    }
                    break;
                }
                case GuidePetLifeStyleRule.StepLifeStyleGet2:
                {
                    if (this._getTxt.visible == true) 
                    {
                        loc2 = GuideTipsManager.getGuideTips(GuideTipsManager.Dir_TL, Language.getString(27205));
                        loc2.x = this._getTxt.x + 18;
                        loc2.y = this._getTxt.y + 18;
                        addChild(loc2);
                        this._eatTxt.mouseEnabled = false;
                    }
                    break;
                }
            }
            return;
        }

        /* internal */ static /* const */EAT: int=0;

        /* internal */ static /* const */GET: int=1;

        /* internal */ /* var */_bg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_avatarbg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_mingBaseItem: PetMingBaseItem;

        /* internal */ /* var */_getTxt: GTextFiled;

        /* internal */ /* var */_eatTxt: GTextFiled;

        /* internal */ /* var */_itemData: PetMingItemData;

        /* internal */ /* var */_flyType: int=-1;
    }
